package week02;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class AuthenticatorFactory {
private static Properties prop = new Properties();
        static {
            try {
                prop.load(new FileInputStream("src/week2/validator_ex/auth.properties"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    public static Authenticator createAuthenticator() {
     KeyValueKeeper keeper = createKeyValueKeeper();
            Encrypter encrypter = createEncrypter();
            return new Authenticator(keeper, encrypter);


    private static KeyValueKeeper createKeyValueKeeper() {
     Authenticator op = null;
            try {
                op = (Operation) Class.forName(prop.getProperty("user")).newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return op;
        }
    }

    private static Encrypter createEncrypter() {
    Authenticator ab = null;
                try {
                    ab = (Operation) Class.forName(prop.getProperty("password")).newInstance();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return ab;
            }
        }

    }
}
